// g++ color.cpp -o color -std=c++14 -fsanitize=address -O2 -Wall -Wextra
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
template<typename T> void up(T &x, T y) { x = (x > y ? x : y); }
template<typename T> void down(T &x, T y) { x = (x < y ? x : y); }
#define rep(i, a, b) for(int i = (a), i##END = (b); i <= (b); i++)
#define Rep(i, a, b) for(int i = (a), i##END = (b); i >= (b); i--)
#define N ((int)(1e5 + 15))

int n, ans, a[N], col[N];
void check()
{
    int sum = 0;
    rep(i, 1, n)
    {
        Rep(j, i - 1, 1)
        {
            if(col[j] == col[i])
            {
                sum += (a[i] == a[j] ? a[j] : 0);
                break;
            }
        }
    }
    up(ans, sum);
}
void dfs(int x)
{
    if(x == n + 1)
    {
        check();
        return;
    }
    col[x] = 0; dfs(x + 1);
    col[x] = 1; dfs(x + 1);
}
void clear()
{
    ans = 0;
}
void solve()
{
    cin >> n; clear(); rep(i, 1, n) cin >> a[i];
    if(n <= 15)
    {
        dfs(1); cout << ans << '\n'; return;
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("check.in", "r", stdin);
    // freopen("check.out", "w", stdout);
    
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    int qwq; cin >> qwq; while(qwq--) solve();
    return 0;
}